Release 10.1A: OpenEdge Development:
Web Services
Modifying a reused SOAP response header
This example shows how you might handle a SOAP header that you first encounter in the response message returned from the Web service, then modify it as the SOAP header for the next request. The response header and its handler are identical to what is used in the header reuse example (see the "Reusing an unchanged SOAP response header" section). This is an example of the header returned from the Web service after a password is added:
Note that the client adds the
<Password>element as a sibling to the<AccessID>element in the existingAuthHeaderheader entry. Another approach is to create and add a newPasswordheader entry as a sibling to theAuthHeaderheader entry itself. Again, the actual approach depends on the Web service itself, in this case theHeaderExampleWeb service. This type of header modification might be used when the Web service and client maintain a consistent context for each other between requests and the operation involved requires authorization or authentication or some other additional context information.Following is the mainline of a procedure that invokes the Web service to reuse the initial SOAP response header by adding a password node to it before passing it back as a SOAP request header. This code:
- Defines several mainline variables, including handles to access the global reused SOAP header (
g_header) and its XML, and a variable to hold the password value (cPassword).- Registers the request header (
ReqHandler) and response header (RespHandler) handlers after connecting to the Web service and instantiating theHeaderSoapport type procedure object.- Runs the
OpenAccessprocedure to invoke the Web service operation that returns theAccessIDvalue in the SOAP response header (see the "Response header handler for returning a header for reuse" section).
- Runs the
HelloWorldprocedure to invoke the next Web service operation, passing back the SOAP response header to the Web service unchanged as the SOAP request header (see the "Request header handler for reusing and modifying a header" section).Note: The header handler processing for Step 4 is different from Step 5, to reflect that the initial SOAP response header is unchanged for one request and modified for the next.- Runs the
HelloSecureWorldprocedure to invoke the next Web service operation, passing back the password-modified SOAP response header as the Web service SOAP request header (see the "Request header handler for reusing and modifying a header" section).- Cleans up the global objects maintained in its context and disconnects from the Web service. Note that one of the objects it deletes is the original SOAP response header saved by the response header handler during execution of the
OpenAccessprocedure.Request header handler for reusing and modifying a header
This is the SOAP request header handler (
ReqHandler) that reuses the initial SOAP response header and adds aPasswordvalue to the existingAuthHeadheader entry to pass along with theAccessIDvalue between the client and Web service:
This code:
- Sends the SOAP request header for the
HelloWorldandHelloSecureWorldrequests (and any request run after runningOpenAccess).- Tests if the global header handle (
g_header) references a valid object:
- If it does not reference an object, the request handler must be running as part of the initial call to
OpenAccessand sets the output parameters to ensure that no initial SOAP request header is sent.- If it does reference an object, the handler passes the global header object as output using the request header parameter (
hHeader) and ensures that the object is not deleted (saving it for use in any further request).
Note: After the first secure request, all future requests (secure or nonsecure) send a request header that includes password information because the password information is never deleted until replaced by a newly-specified password.- Tests if a password has been specified for the current Web service request, indicated by any
cPasswordvalue that is not the Unknown value (?). If the current Web service request is nonsecure (as with theHelloWorldoperation), all work has been done and the request handler can end. If the current Web service request is secure (as with theHelloSecureWorldoperation), the request handler adds the password information to the SOAP request header, as follows:
- Creates the XML x-document and x-noderef objects to manipulate the SOAP header.
- Creates the SOAP header entryref object (
hHeaderEntryref) to access SOAP header entries and defines the namespace (ClientNS) used for defining the SOAP header entry for this request.Note: The handler is adding the password information to an existing SOAP header entry. If it was adding a new header entry to hold the information, it would invoke the- Returns the existing header entry from the saved global SOAP header object using the
GET-HEADER-ENTRY( )method on the SOAP header object and accesses the XML root node of the entry using theGET-NODE( )method on the SOAP header entryref object.ADD-HEADER-ENTRY( )method to add the header entry to contain the new XML for it.- Imports the header entry root node into an x-document object in order to access and modify the XML for the header entry, and also deletes any password data from a previous secure request before adding the currently-specified password data.
- Adds the
<Password>element as a sibling of the<AccessID>element.- Adds the
<Password>element value.- Replaces the entire existing header entry in the global SOAP header object with the header entry updated in the x-document object.
- Sets the password value (
cPassword) to unknown (?), which retains the current password in the header entry until it is explicitly changed incPassword. Deletes all of the helper XML and SOAP header entryref objects created in the header handler.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |